﻿using HtmlAgilityPack;
using InternetSpiderLib;
using System;
using System.Collections.Generic;
using System.Text;

namespace WeChatGZHTextExtractor
{
    /// <summary>
    /// 内容的数据提取器
    /// </summary>
    public class BodyHtmlDocumentExtractingSceneAction : ISceneAction
    {
        private ISceneAction ChildAction { get; set; }

        public BodyHtmlDocumentExtractingSceneAction(ISceneAction scene)
        {
            ChildAction = scene;
        }

        public void Run(DataBox data)
        {
            var body = data.Get<string>(PublicKey.HtmlInfo.BODY);
            if (body == null)
                return;

            HtmlDocument document = new HtmlDocument();
            document.LoadHtml(body);
            data.Set(document);

            ChildAction?.Run(data);
        }
    }
}
